<?php

namespace App\Http\Controllers\NonPublicVersion;

use App\Http\Controllers\ErrorCode;
use App\Http\Controllers\SuccessCode;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\PayConfig as Model;
use App\Http\Controllers\Common;
use Cache;
class PayConfig extends Controller
{
    use Common;
    public function index(Request $request)
    {
        $pay_config = Model::orderBy("create_time","desc")->first();
        if(!$pay_config){
            $id = Model::insertGetId([
                'wxpay'=>1,
                'alipay'=>1,
                'create_time'=>time()
            ]);
        }
        $pay_config = Model::orderBy("create_time","desc")->first();
        return view('nonPublicVersion.payConfig.index', [
            'info' => $pay_config,
        ]);
    }
    public function store(Request $request)
    {
        $id = Model::insertGetId([
            'wxpay'=>intval($_POST['wxpay']),
            'alipay'=>intval($_POST['alipay']),
            'create_time'=>time()
        ]);
        if ($id !== false) {
            return $this->getView([], SuccessCode::EDIT_SUCCESS);
        } else {
            return $this->getView([], ErrorCode::EDIT_ERROR);
        }
    }
    public function payType(Request $request)
    {
        $data = Model::orderBy("create_time","desc")->first();
        return $this->getView($data,SuccessCode::GET_SUCCESS);
    }
}
